<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户位置分析测试</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            max-width: 1000px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
        .content {
            padding: 30px;
        }
        .section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #e0e0e0;
            border-radius: 10px;
            background: #fafafa;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: 600;
            color: #555;
        }
        .form-group input, .form-group textarea {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 14px;
            transition: border-color 0.3s;
        }
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 600;
            margin-right: 10px;
        }
        .output {
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            padding: 15px;
            height: 400px;
            overflow-y: auto;
            font-family: 'Courier New', monospace;
            font-size: 12px;
            white-space: pre-wrap;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📍 用户位置分析测试</h1>
            <p>测试用户位置分析API功能</p>
        </div>

        <div class="content">
            <div class="section">
                <h2>⚙️ 服务配置</h2>
                <div class="form-group">
                    <label for="baseUrl">服务端地址:</label>
                    <input type="text" id="baseUrl" value="http://localhost:8080" placeholder="请输入服务端地址">
                </div>
                <div class="form-group">
                    <label for="token">认证Token:</label>
                    <input type="text" id="token" placeholder="请输入用户认证Token">
                </div>
            </div>

            <div class="section">
                <h2>📍 用户位置分析</h2>
                <div class="form-group">
                    <label for="userLocationDesc">描述信息:</label>
                    <input type="text" id="userLocationDesc" placeholder="请输入描述信息">
                </div>
                <div class="form-group">
                    <label for="userLocationMessage">用户信息描述 (支持Markdown格式):</label>
                    <textarea id="userLocationMessage" rows="10" placeholder="请详细描述用户信息，包括行业、目标客户群体、营销需求等。支持Markdown格式。"></textarea>
                </div>
                <div class="controls">
                    <button id="analyzeBtn" class="btn">分析用户位置</button>
                    <button id="clearBtn" class="btn">清空结果</button>
                    <button id="exampleBtn" class="btn">加载示例</button>
                </div>
            </div>

            <div class="section">
                <h2>📊 分析结果</h2>
                <div id="output" class="output">等待分析...</div>
            </div>
        </div>
    </div>

    <script>
        const baseUrlEl = document.getElementById('baseUrl');
        const tokenEl = document.getElementById('token');
        const userLocationDescEl = document.getElementById('userLocationDesc');
        const userLocationMessageEl = document.getElementById('userLocationMessage');
        const outputEl = document.getElementById('output');
        const analyzeBtn = document.getElementById('analyzeBtn');
        const clearBtn = document.getElementById('clearBtn');
        const exampleBtn = document.getElementById('exampleBtn');

        function init() {
            analyzeBtn.addEventListener('click', analyzeUserLocation);
            clearBtn.addEventListener('click', clearOutput);
            exampleBtn.addEventListener('click', loadExample);
            
            // 设置默认值
            tokenEl.value = 'test-token-123';
        }

        async function analyzeUserLocation() {
            const message = userLocationMessageEl.value.trim();
            const desc = userLocationDescEl.value.trim();
            const token = tokenEl.value.trim();
            const baseUrl = baseUrlEl.value.trim();
            
            if (!message) {
                alert('请输入用户信息描述');
                return;
            }
            
            if (!token) {
                alert('请输入认证Token');
                return;
            }
            
            try {
                analyzeBtn.disabled = true;
                clearOutput();
                
                const requestData = { 
                    message: message,
                    desc: desc
                };
                
                const response = await fetch(`${baseUrl}/api/client/index/addUserLocation?token=${encodeURIComponent(token)}`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(requestData)
                });
                
                if (!response.ok) {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }
                
                const result = await response.json();
                
                if (result.code === 200) {
                    appendOutput('分析结果:\n');
                    appendOutput(JSON.stringify(result.data, null, 2));
                } else {
                    throw new Error(result.message || '分析失败');
                }
                
            } catch (error) {
                appendOutput(`错误: ${error.message}`);
            } finally {
                analyzeBtn.disabled = false;
            }
        }
        
        function clearOutput() {
            outputEl.textContent = '';
        }
        
        function appendOutput(content) {
            outputEl.textContent += content;
            outputEl.scrollTop = outputEl.scrollHeight;
        }

        function loadExample() {
            const exampleText = `# 用户信息分析

## 基本信息
- 行业：教育培训
- 细分领域：K12在线教育
- 主要业务区域：一线城市

## 目标客户
- 年龄：30-45岁家长群体
- 收入水平：中等收入
- 主要关注：孩子学习成绩提升

## 营销需求
- 推广渠道：社交媒体、搜索引擎
- 内容重点：教育理念、学习方法
- 品牌定位：专业、可信赖的教育伙伴`;
            
            userLocationMessageEl.value = exampleText;
        }

        document.addEventListener('DOMContentLoaded', init);
    </script>
</body>
</html> 